import axios from 'axios'
import { baseUrl } from './api.config'

let token = ''

export default function(url, params, methodType = 'GET') {
    let isGET = methodType === "GET"
    return new Promise((resolve, reject) => {
        axios.request({
            url: url,
            method: methodType,
            baseURL: baseUrl,
            data: isGET ? {} : params,
            header: {
                "stateToken": token
            },
            params: isGET ? params : {},
            timeout: 1000 * 60,
        }).then(res => {
            token = res.headers["stateToken"]
            console.log(res.data.data)
            if (res.data.success) {
                resolve(res.data.data)
            }
        }).catch(err => {
            if (err.message.includes('timeout')) {
                // 请求超时
            }
            reject(err)
        }).finally(() => {
            // 请求结束 
        })
    })
}